<?php

class ARP {

    public static function kontaktniUdajeZmena() {
        checkUser();
        $query = getAdresaByUser();        
        while ($row = mysql_fetch_array($query)) {
            if ($row["stav"] == Settings::$fakturacni) {
                $GLOBALS["ulice"] = $row["ulice"];
                $GLOBALS["jmeno"] = $row["jmeno"];
                $GLOBALS["prijmeni"] = $row["prijmeni"];
                if (isset($row["ic"])){
                    $GLOBALS["ic"] = $row["ic"];
                }else{
                    $GLOBALS["ic"] = "";
                }                      
                if ($row["firma"] == "null"){
                    $GLOBALS["firma"] = "";
                }  else {
                    $GLOBALS["firma"] = $row["firma"];                
                }                 
                $GLOBALS["mesto"] = $row["mesto"];                
                $GLOBALS["psc"] = $row["psc"]; 
                if ($row["stat"] == 1){
                    $GLOBALS["statCR"] = 'selected="selected"';
                }else{
                    $GLOBALS["statSLO"] = 'selected="selected"';
                }
                $GLOBALS["phone"] = $row["mobil"];
                $GLOBALS["mail"] = getUser()->getEmail();
            } else {
                $GLOBALS["djmeno"] = $row["jmeno"];
                $GLOBALS["dprijmeni"] = $row["prijmeni"];
                if ($row["firma"] == "null"){
                    $GLOBALS["dfirma"] = "";
                }  else {
                    $GLOBALS["dfirma"] = $row["firma"];                
                }       
                $GLOBALS["dulice"] = $row["ulice"];
                $GLOBALS["dmesto"] = $row["mesto"];  
                $GLOBALS["dpsc"] = $row["psc"];    
                if ($row["stat"] == 1){
                    $GLOBALS["dstatCR"] = 'selected="selected"';
                }else{
                    $GLOBALS["dstatSLO"] = 'selected="selected"';
                }
            }
        }
        echo constructZadaniFakUdajuFull();
        exit();
    }

    public static function getKosikPageData() {
        checkUser();
        echo constructCartWithPrice();
        exit();
    }

    public static function getPrejitKPokladne() {
        checkUser();
        echo constructZpusobPlatby();
        exit();
    }

    public static function getKontakt() {
        checkUser();
        echo parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/Kontakt", "../"));
    }
    public static function getVyhledaniVelikosti() {
        checkUser();
        echo parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/vyhledaniVelikosti", "../"));
    }
    public static function getInfoZnac() {
        checkUser();
        echo parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/InformaceOZnackach", "../"));
    }

    public static function getTabulkaVelikosti() {
        checkUser();
        echo parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/TabulkaVelikosti", "../"));
    }

    public static function prejdiNaZadaniFakUdaju() {
        echo constructZadaniFakUdaju();
        exit();
    }

    public static function prijmiObjednavkuHotove() {
        checkUser();
        getUser()->setPlatba(Settings::$platba_typ_hotove);
        vytvorObednavku();
        echo parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/ObednavkaPrijata", "../"));
        exit();
    }

    public static function prijmiObjednavkuDobirka() {
        checkUser();
        getUser()->setPlatba(Settings::$platba_typ_dobirka);
        vytvorObednavku();
        echo parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/ObednavkaPrijata", "../"));
        exit();
    }
    public static function prijmiObjednavkuUcet() {
        checkUser();
        getUser()->setPlatba(Settings::$platba_typ_ucet);
        vytvorObednavku();
        echo parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/ObednavkaPrijata", "../"));
        exit();
    }

    public static function spravaObjednavekAdmin() {
        echo vytvorTabulkuObjednavekAdmin();
        exit();
    }

    public static function spravaObjednavekUser() {
        echo vytvorTabulkuObjednavekAdmin(null, true);
        exit();
    }

}

function constructZpusobPlatby() {
    $ret = "";
    $ret = parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/zpusobPlatby", "../"));
    return $ret;
}

function constructZadaniFakUdaju() {
    if (isRegistered()) {
        $GLOBALS["fakUdajeMail"] = "";
        $GLOBALS["fakUdajeheslo"] = "";
    } else {
        $GLOBALS["fakUdajeMail"] = parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/fakUdajeMail", "../"));
        $GLOBALS["fakUdajeheslo"] = parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/fakUdajeHeslo", "../"));
    }
    $ret = "";
    $ret = parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/FakturacniUdaje", "../"));
    return $ret;
}

function constructZadaniFakUdajuFull() {
    if (isRegistered()) {
        $GLOBALS["fakUdajeMail"] = "";
        $GLOBALS["fakUdajeheslo"] = "";
    } else {
        $GLOBALS["fakUdajeMail"] = parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/fakUdajeMailFull", "../"));
        $GLOBALS["fakUdajeheslo"] = parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/fakUdajeHesloFull", "../"));
    }
    $ret = "";
    $ret = parseTemplate(loadTemplateWithPath(Settings::$template_path . "eshop/itemListDiv/FakturacniUdajeFull", "../"));
    return $ret;
}

?>
